<template>
	<view>
		<!-- 自定义导航 -->
		<uni-nav-bar left-icon="left"   :statusBar="true" titleSize="30px" leftText="返回" rightText="保存"  title="关联产品"  @clickLeft="back" @clickRight="addBtn" :fixed="true" backgroundColor="#3286ed" color="#fff"/>
	<!-- 搜索框 -->
	<u-search   v-model.enter="form.warehouseName" @search="searchFn" @custom="customFn" style="height;40px;background-color: #fff;padding: 10px;margin-bottom: 5px;"   @clear="clearFn" :clearabled="true" showAction  height='30' placeholder="请输入产品名" shape="square" actionText='搜索' @change="searchangeFn"></u-search>
	  
		 <uni-table border :stripe="true" type="selection" @selection-change="changeFn" emptyText="暂无更多数据" >
		 	<!-- 表头行 -->
		 	<uni-tr>
		 		<uni-th align="center" width="80px">仓库名称</uni-th>
		 		<uni-th align="center" width="100px">省份</uni-th>
				<uni-th align="center" width="100px">负责人</uni-th>
		 		 
		 	</uni-tr>
		 	<!-- 表格数据行 -->
		 	<uni-tr  v-for="(item,index) in list" :key="index">
		 		<uni-td  align="center">{{item.warehouseName}}</uni-td>
		 		<uni-td  align="center">{{item.region}}</uni-td>
		 		 <uni-td  align="center">{{item.responsibleUserName}}</uni-td>
		 		
		 	</uni-tr>
		 </uni-table>
	</view>
</template>
<script>
	import {listWarehouse} from '@/api/warehouse/warehouse.js'
	export default {
		data() {
			return {
				list:[],
				form:{
					warehouseName:'',
					pageSize:100,
					pageNum:1
				},
				 checkWarehouseName:'',
				 warehouseNo:'',
				 type:" ",
				 responsibleUser:'',
				 responsibleUserName:'',
				 
			};
		},
		onLoad(e) {
			console.log(e);
			this.type=e.type
		},
		created() {
			this.getlist()
		},
		methods:{
			searchangeFn(){
				this.getlist()
			},
			clearFn(){
				this.form.warehouseName=''
				this.getlist()
			},
			customFn(){
				if(!this.form.warehouseName){
					return false
				} 
				this.getList()
			},
			searchFn(){
				this.getlist()
			},
			async getlist(){
			   let res=await listWarehouse(this.form)	
			   console.log(res.rows);
			   this.list=res.rows
			},
			changeFn(e){
				console.log(e);
				this.checkWarehouseName=''
				this.warehouseNo=''
				this.responsibleUser=''
				this.responsibleUserName=''
				 this.list.forEach((item,index)=>{
					 e.detail.index.forEach(items=>{
						 if(index==items){
							  
							 this.checkWarehouseName+=item.warehouseName+''
							 this.warehouseNo+=item.warehouseNo+""
							 this.responsibleUser+=item.responsibleUser+''
							 this.responsibleUserName+=item.responsibleUserName+''
						 }
					 })
				 })
				 console.log();
				},
				// 保存
				addBtn(){
					 // 1. 获取当前页面栈实例（此时最后一个元素为当前页）
					let pages = getCurrentPages() 
					console.log(pages);
					 // 2. 上一页面实例
					// 注意是length长度，所以要想得到上一页面的实例需要 -2
					// 若要返回上上页面的实例就 -3，以此类推
				   let prevPage = pages[pages.length -2] 
				   // 3. 给上一页面实例绑定getValue()方法和参数（注意是$vm）
				    prevPage.$vm.getValueS({checkWarehouseName:this.checkWarehouseName,type:this.type,warehouseNo:this.warehouseNo, responsibleUser:this.responsibleUser,responsibleUserName:this.responsibleUserName}) 
					// 4. 返回上一页面
					
					 uni.navigateBack({
						 delta: 1 // 返回的页面数
					 })
					  
				},
			 // addBtn(){
				//  uni.navigateBack({
				//  	url:'/pages/order/addOrder/addOrder?nwarehouseName='+this.checkWarehouseName
				//  })
			 // },
			back(){
				uni.navigateBack({
					delta:1
				})
			},
		}
	}
</script>

<style lang="scss">

</style>
